package com.fbli.test.controller;

import com.fbli.test.common.entity.task.*;
import com.fbli.test.common.result.ResultParam;
import com.fbli.test.common.result.ResultSend;
import com.fbli.test.entity.Project;
import com.fbli.test.service.TaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = {"任务功能"})
@RestController
@RequestMapping("/task")
public class TaskController {
    @Autowired
    TaskService taskService;
    @ApiOperation("添加任务")
    @PostMapping("/addTask")
    public ResultParam addTask(@RequestBody TaskAddReqMsg taskAddReqMsg){
        boolean b = taskService.addTask(taskAddReqMsg);
        if (b){
            return ResultSend.success("添加成功！");
        }else {
            return ResultSend.fail("添加失败！");
        }
    }
    @ApiOperation("编辑任务")
    @PostMapping("/editTask")
    public ResultParam editTask(@RequestBody TaskEditReqMsg taskEditReqMsg){
        long id = taskEditReqMsg.getId();
        if (id>0){
            boolean b = taskService.editTask(taskEditReqMsg);
            if (b){
                return ResultSend.success("修改成功！");
            }else {
                return ResultSend.fail("修改失败！");
            }
        }else {
            return ResultSend.fail("任务不存在！");
        }
    }
    @ApiOperation("获取当前用户当前项目下的所有任务和项目数据")
    @PostMapping("/selectAllTask")
    public ResultParam selectAllTask(@RequestBody TaskReqMsg taskReqMsg){
        List<Project> taskProjectProjectIters = taskService.selectTask(taskReqMsg);
        if (taskProjectProjectIters==null){
            return ResultSend.fail("当前用户、项目不存在");
        }
        return ResultSend.success(taskProjectProjectIters);
    }
    @ApiOperation("获取当前用户当前项目下的所有任务")
    @PostMapping("/selectAll")
    public ResultParam selectAll(@RequestBody TaskPageReqMsg taskPageReqMsg){
        TaskPageResMsg taskPageResMsg = taskService.selectAll(taskPageReqMsg);
        if (taskPageResMsg==null){
            return ResultSend.fail("当前用户、项目不存在");
        }
        return ResultSend.success(taskPageResMsg);
    }
    @ApiOperation("获取当前用户当前项目的项目详情")
    @PostMapping("/selectTaskShow")
    public ResultParam selectTaskShow(@RequestBody TaskReqMsg taskReqMsg){
        List<Project> taskShow = taskService.selectTaskShow(taskReqMsg);
        if (taskShow==null){
            return ResultSend.fail("当前用户、项目不存在");
        }
        return ResultSend.success(taskShow);
    }
}
